package cn.com.taiji.pos.service.impl;

import cn.com.taiji.pos.common.util.MD5;
import cn.com.taiji.pos.entity.SystemAclUser;
import cn.com.taiji.pos.mapper.SystemAclUserMapper;
import cn.com.taiji.pos.service.ISystemAclUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户信息表 服务实现类
 * </p>
 *
 * @author
 * @since 2021-03-01
 */
@Service
public class SystemAclUserServiceImpl extends ServiceImpl<SystemAclUserMapper, SystemAclUser> implements ISystemAclUserService {
    @Autowired
    private SystemAclUserMapper systemAclUserMapper;


    @Override
    public SystemAclUser findByLoginName(String loginName) {
        QueryWrapper<SystemAclUser> systemAclUserWrapper = new QueryWrapper<>();
        systemAclUserWrapper.eq("LOGIN_NAME", loginName);
        return systemAclUserMapper.selectOne(systemAclUserWrapper);
    }

    @Override
    public SystemAclUser findByLoginNameAndPassword(SystemAclUser loginUser) {
        QueryWrapper<SystemAclUser> systemAclUserWrapper = new QueryWrapper<>();
        systemAclUserWrapper.eq("LOGIN_NAME", loginUser.getLoginName());
        systemAclUserWrapper.eq("PASSWORD", MD5.MD5Encode(loginUser.getPassword()));
        return systemAclUserMapper.selectOne(systemAclUserWrapper);
    }

    @Override
    public boolean hasAuthority(String resourceId, String userId) {
        return systemAclUserMapper.hasAuthority(resourceId, userId);
    }
}
